package org.sgsm.dungeon.generator;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.StringTokenizer;

public class DgFile
{
  protected String _path;
  protected String _fileName;

  public DgFile(String pPath, String pFileName)
  {
    _path = pPath;
    _fileName = pFileName;
  }

  public void postFile()
  {
    String tmpPath = "";
    StringTokenizer tokenizer = new StringTokenizer(_path, "\\");
    while (tokenizer.hasMoreTokens())
    {
      tmpPath += "\\" + tokenizer.nextToken();
      creationFile(tmpPath);
    }
  }

  public PrintWriter getBufferFichier()
  {
    try
    {
      return new PrintWriter(new FileWriter(getFilePath()), true);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    return null;
  }

  protected String getFilePath()
  {
    return _path + "\\" + _fileName;
  }

  private void creationFile(String path)
  {
    File dossier = new File(path);
    if (!dossier.exists())
    {
      dossier.mkdir();
    }
  }
}
